import { createApp } from "vue";
import App from "./App.vue";
import "./index.css";
import { createI18n } from "vue-i18n";
import i18_zh from "./i18n/i18_zh";
import i18_en from "./i18n/i18_en";
import "normalize.css/normalize.css";
import "@/vendor/Export2Execl.js";

// import echarts from "echarts";

import "../theme/index.css";
// import "./icons";//配置不了没有使用

import router from "./router";
const app = createApp(App);
app.use(router);
// app.use(VueI18n);
// Vue.prototype.$echarts = echarts;
import ElementPlus from "element-plus";
// app.use(ElementPlus)

//

import {
  ElButton,
  ElContainer,
  ElAside,
  ElHeader,
  ElMain,
  ElFooter,
  ElMenu,
  ElSubmenu,
  ElMenuItemGroup,
  ElMenuItem,
  ElForm,
  ElFormItem,
  ElInput,
  ElPopover,
  ElTag,
  ElCard,
  ElTable,
  ElTableColumn,
  ElPagination,
  ElDialog,
  ElPopconfirm,
  ElUpload,
  ElLoading,
  ElSelect,
  ElOption,
  ElRadioGroup,
  ElRadio,
  ElCascader,
  ElCheckbox,
  ElInputNumber,
  ElRate,
} from "element-plus";

const orderStatus = {
  0: "待支付",
  1: "已支付",
  2: "配货完成",
  3: "出库成功",
  4: "交易成功",
  "-1": "手动关闭",
  "-2": "超时关闭",
  "-3": "商家关闭",
};

//设置当前语言
var langType = window.localStorage.getItem("langType") ? window.localStorage.getItem("langType") : (window.navigator.language || window.navigator.browserLanguage).toLowerCase(); //直接获取浏览器的默认语言
if (langType.indexOf("zh") >= 0) {
  langType = "zh";
} else {
  langType = "en";
}
if (!window.localStorage.getItem("langType")) {
  window.localStorage.setItem("langType", langType);
}

const i18n = new createI18n({
  locale: langType, //语言标识
  messages: {
    zh: i18_zh,
    en: i18_en,
  },
});

app.use(i18n);

app
  .use(ElRate)
  .use(ElButton)
  .use(ElContainer)
  .use(ElAside)
  .use(ElHeader)
  .use(ElMain)
  .use(ElFooter)
  .use(ElMenu)
  .use(ElSubmenu)
  .use(ElMenuItemGroup)
  .use(ElMenuItem)
  .use(ElForm)
  .use(ElFormItem)
  .use(ElInput)
  .use(ElPopover)
  .use(ElTag)
  .use(ElCard)
  .use(ElTable)
  .use(ElTableColumn)
  .use(ElPagination)
  .use(ElDialog)
  .use(ElPopconfirm)
  .use(ElUpload)
  .use(ElLoading)
  .use(ElSelect)
  .use(ElOption)
  .use(ElRadioGroup)
  .use(ElRadio)
  .use(ElCascader)
  .use(ElCheckbox)
  .use(ElInputNumber);

app.config.globalProperties.$filters = {
  orderMap(status) {
    return orderStatus[status] || "weizhizhuangtai";
  },
  prefix(url) {
    if (url && url.startsWith("http")) {
      return url;
    } else {
      url = `http://backend-api-02.newbee.ltd${url}`;
      return url;
    }
  },
};

app.mount("#app");
